<template>
  <div class="head-container">
    <!-- 搜索 -->
    <div v-show="sup_this.searchToggle">
      <el-select v-model="paramBean.selfStateList" size="mini" style="width: 300px;" multiple clearable placeholder="请选择状态">
        <el-option v-for="item in dicts.bus_self_state" :key="item.id" :label="item.dictName" :value="item.dictCode"/>
      </el-select>
      <el-input v-model="paramBean.busOtherCpyName" clearable placeholder="输入客户搜索" style="width: 200px;" class="filter-item" @keyup.enter.native="sup_this.toQuery"/>
      <el-input v-model="paramBean.sysGenCode" clearable placeholder="输入系统编号搜索" style="width: 200px;" class="filter-item" @keyup.enter.native="sup_this.toQuery"/>
      <el-button class="filter-item" size="mini" type="success" icon="el-icon-search" @click="sup_this.toQuery">搜索</el-button>
      <el-button class="filter-item" size="mini" type="warning" icon="el-icon-refresh-left" @click="sup_this.resetQuery()">重置</el-button>
    </div>
    <div class="crud-opts">
      <el-button
        v-permission="['SYS_ADMIN','COMMON_ADMIN','FINTRX_RCV_ALL','FINTRX_RCV_CREATE']"
        class="filter-item"
        size="mini"
        type="primary"
        icon="el-icon-plus"
        @click="toAdd">新增</el-button>
      <el-button
        v-permission="['SYS_ADMIN','COMMON_ADMIN','FINTRX_RCV_ALL','FINTRX_RCV_SUBMIT']"
        v-loading="submitLoading"
        class="filter-item"
        size="mini"
        type="success"
        icon="el-icon-check"
        @click="doMultiSubmit">提交</el-button>
      <el-button
        v-permission="['SYS_ADMIN','COMMON_ADMIN','FINTRX_RCV_ALL','FINTRX_RCV_CREATE']"
        class="filter-item"
        size="mini"
        type="primary"
        icon="el-icon-document-copy"
        @click="toCopy">复制</el-button>
      <el-button
        v-permission="['SYS_ADMIN','COMMON_ADMIN','FINTRX_RCV_ALL','FINTRX_RCV_DELETE']"
        v-loading="deleteLoading"
        class="filter-item"
        size="mini"
        type="danger"
        icon="el-icon-delete"
        @click="doMultiDelete">删除</el-button>
      <DestoryOpt
        v-permission="['SYS_ADMIN','COMMON_ADMIN','FINTRX_RCV_ALL','FINTRX_RCV_DESTORY']"
        v-loading="destoryLoading"
        :sup_this="sup_this"
        @doMultiDestory="doMultiDestory">注销</DestoryOpt>
      <el-button
        v-permission="['SYS_ADMIN','COMMON_ADMIN','FIN_VOUCHER_ALL','FIN_VOUCHER_CREATE']"
        class="filter-item"
        size="mini"
        type="primary"
        icon="el-icon-plus"
        @click="toVoucher">生成凭证</el-button>
      <DataGridOpts :sup_this="sup_this" @refreshClick="refreshClick" @searchClick="searchClick" />
    </div>
  </div>
</template>

<script>
import finTrxRcv from '@/api/fin/FinTrxRcv'
import finVoucher from '@/api/fin/FinVoucher'

export default {
  components: { },
  dictTypes: ['bus_self_state'],
  props: {
    paramBean: {
      type: Object,
      required: true
    },
    sup_this: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      deleteLoading: false,
      submitLoading: false,
      destoryLoading: false
    }
  },
  methods: {
    refreshClick() {
      this.sup_this.init()
    },
    searchClick() {
      this.sup_this.toggleSearch()
    },
    beforeCreate() {
    },
    doMultiDelete() {
      const _this = this.sup_this
      _this.doMultiDelete(finTrxRcv.deleteUrl(), this)
    },
    toCopy() {
      const _this = this.sup_this
      const selectMainId = _this.getSelectMainId()
      if (!selectMainId) {
        return
      }
      const _thisForm = _this.$refs.form
      _thisForm.initDataOfBefore()
      _thisForm.copyData(selectMainId)
    },
    doMultiSubmit() {
      const _this = this.sup_this
      _this.doMultiSubmit(finTrxRcv.submitUrl(), this)
    },
    doMultiDestory(selectIds, isSubmit, busRmk) {
      const _this = this.sup_this
      _this.doMultiDestory(finTrxRcv.destoryUrl(), selectIds, isSubmit, this, busRmk)
    },
    toChange() {
      const _this = this.sup_this
      const selectBusId = _this.getSelectBusId()
      if (!selectBusId) {
        return
      }
      const _thisForm = this.sup_this.$refs.form
      _thisForm.initDataOfBefore()
      _thisForm.changeData(selectBusId)
    },
    toAdd() {
      const _this = this.sup_this.$refs.form
      _this.initDataOfBefore()
      _this.addData()
    },
    toVoucher() {
      const _this = this.sup_this
      const busRelList = []
      _this.selectedGridRows.forEach(row => {
        busRelList.push({ fromBusModule: row.busModule, fromBusClass: row.busClass, fromCode: row.sysGenCode, fromId: row.id })
      })
      if (busRelList.length === 0) {
        this.$message({
          message: '请选择记录',
          type: 'warning'
        })
        return
      }
      this.$confirm('确认要生成凭证?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        center: true
      }).then(() => {
        const data = { busRelList: busRelList }
        finVoucher.toAddFromFinTrx(data).then(res => {
          this.$router.push({ path: '/fin/finvoucher' })
        }).catch(err => {
          console.log(err)
        })
      }).catch(() => {
      })
    }
  }
}
</script>
